﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Net;

using EHTWebsite.Code;
using EHTWebsiteProject.Code.BLL;
using System.Resources;
using System.Threading;
using System.Globalization;
using System.Text;

namespace EHTWebsiteProject.Administrator
{
    public partial class EHTFrontPage : System.Web.UI.Page
    {
        public Boolean IsVN = true;
        private String languageCode = "vi-VN";
        private String message = "";
        private ResourceManager rm = new ResourceManager("Resources.SiteMap", System.Reflection.Assembly.Load("App_GlobalResources"));

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                AjaxPro.Utility.RegisterTypeForAjax(typeof(EHTWebsiteProject.Administrator.EHTFrontPage));
                try
                {
                    languageCode = Session[HangSo.LANGUAGE_CODE].ToString();
                    Session["NgonNgu"] = languageCode;
                    if (languageCode == "en-us")
                    {
                        IsVN = false;
                    }

                }
                catch (Exception ex)
                {
                }
                try
                {
                    message = Request.QueryString["Message"].ToString();
                    if (message != "")
                        ltrErorr.Text = HelpMethod.ApplySuccess(message);
                }
                catch
                {

                }
                Thread.CurrentThread.CurrentCulture = new CultureInfo(languageCode);
                LoadLanguage(Thread.CurrentThread.CurrentCulture);
                LoadThongTinCongty();                
            }
        }

        /// <summary>
        /// Ham load ngon ngu
        /// </summary>
        /// <param name="ci"></param>
        public void LoadLanguage(CultureInfo ci)
        {
            lbDichVu.Text = rm.GetString("lbDichVu", ci);
            lbFrontPage.Text = rm.GetString("lbFrontPage", ci);
            lbHelp.Text = rm.GetString("lbHelp", ci);
            lbSave.Text = rm.GetString("lbSave", ci);
            lbThongTinCongTy.Text = rm.GetString("lbThongTinCongTy", ci);
            lbHoTro.Text = rm.GetString("lbHoTro",ci);

            lbDiaChiOther.Text = rm.GetString("lbDiaChiOther", ci);
            lbDiaChiVN.Text = rm.GetString("lbDiaChiVN", ci);
            lbTenCongtyOther.Text = rm.GetString("lbTenCongtyOther", ci);
            lbTenCongTyVN.Text = rm.GetString("lbTenCongTyVN", ci);
            lbThongTinCongTy.Text = rm.GetString("lbThongTinCongTy", ci);
            lbEmail.Text = rm.GetString("lbEmail", ci);

            lbEmailPass.Text = rm.GetString("lbEmailPass", ci);
            lbDienThoai.Text = rm.GetString("lbDienThoai", ci);
            lbMaSoThue.Text = rm.GetString("lbMaSoThue", ci);
            lbTaiKhoan.Text = rm.GetString("lbTaiKhoan", ci);
            lbGioiThieuVN.Text = rm.GetString("lbGioiThieuVN", ci);
            lbGioiThieuOther.Text = rm.GetString("lbGioiThieuOther", ci);
            lbHinhANhCongTy.Text = rm.GetString("lbHinhANhCongTy",ci);
        }

        public Boolean ValidateData()
        {
            Boolean flag = true;
            if (txtTenCongTyVN.Text == "" || txtTenCongtyOther.Text == "")
            {
                if (IsVN == true)
                    message = HangSo.check_VN;
                else
                    message = HangSo.check_Other;
                flag = false;
            }
            if (HelpMethod.IsEmail(txtEmail.Text) == false)
            {
                if (IsVN == true)
                    message = HangSo.Eorr_Mail;
                else
                    message = HangSo.Eorr_MailOther;
                flag = false;
            }
            return flag;
        }


      
        public void LoadThongTinCongty()
        {
            ThongTinCongTy theThongTin = ThongTinCongTyProvider.GetThongTinCongTyByCongTyID(HangSo.COMPANY_ID);
            txtDiaChiOther.Text = theThongTin.DiaChiOther;
            txtDiaChiVN.Text = theThongTin.DiaChiVN;
            txtDienThoai.Text = theThongTin.DienThoai;
            txtEmail.Text = theThongTin.Email;

            txtFax.Text = theThongTin.Fax;
            txtHotline.Text = theThongTin.Hotline;
            txtMaSoThue.Text = theThongTin.MaSoThue;
            txtSologanOther.Text = theThongTin.SologanOther;
            txtSologanVN.Text = theThongTin.SologanVN;
            txtTaiKhoan.Text = theThongTin.TaiKhoan;
            txtTenCongtyOther.Text = theThongTin.TenCongTyOther;
            txtTenCongTyVN.Text = theThongTin.TenCongTyVN;
            txtWebSite.Text = theThongTin.Website;
            txtEmailPass.Attributes.Add("Pass", theThongTin.EmailPass);
            if (theThongTin.GioiThieuTomTatVN != "")
                RadNoiDUngVN.Content = theThongTin.GioiThieuTomTatVN + "-------" + theThongTin.GioiThieuVN;
            else
                RadNoiDUngVN.Content = theThongTin.GioiThieuVN;
            if (theThongTin.GioiThieuTomTatOther != "")
                RadNoiDungOther.Content = theThongTin.GioiThieuTomTatOther + "-------" + theThongTin.GioiThieuOther;
            else
                RadNoiDungOther.Content = theThongTin.GioiThieuOther;

        }


        protected void ImgSave_Click(object sender, ImageClickEventArgs e)
        {
            ThongTinCongTy theThongTin = new ThongTinCongTy();
            theThongTin.DiaChiOther = txtDiaChiOther.Text;
            theThongTin.DiaChiVN = txtDiaChiVN.Text;
            theThongTin.DienThoai = txtDienThoai.Text;
            theThongTin.Email = txtEmail.Text;
            theThongTin.EmailPass = txtEmailPass.Text;
            theThongTin.Fax = txtFax.Text;
            theThongTin.Hotline = txtHotline.Text;
            theThongTin.MaSoThue = txtMaSoThue.Text;
            theThongTin.SologanOther = txtSologanOther.Text;
            theThongTin.SologanVN = txtSologanVN.Text;
            theThongTin.TaiKhoan = txtTaiKhoan.Text;
            theThongTin.TenCongTyOther = txtTenCongtyOther.Text;
            theThongTin.TenCongTyVN = txtTenCongTyVN.Text;
            theThongTin.Website = txtWebSite.Text;
            theThongTin.LogoUrl = "";
            theThongTin.FooterOther = "";
            theThongTin.FooterVN = "";

            int index1 = RadNoiDungOther.Content.IndexOf("------");
            int index2 = RadNoiDUngVN.Content.IndexOf("------");
            try
            {
                theThongTin.GioiThieuTomTatOther = RadNoiDungOther.Content.Substring(0, index1).ToString();
                theThongTin.GioiThieuOther = RadNoiDungOther.Content.Remove(0, index1 + 7).ToString();
            }
            catch
            {
                theThongTin.GioiThieuTomTatOther = "";
                theThongTin.GioiThieuOther = RadNoiDungOther.Content;
            }

            try
            {
                theThongTin.GioiThieuTomTatVN = RadNoiDUngVN.Content.Substring(0, index2).ToString();
                theThongTin.GioiThieuVN = RadNoiDUngVN.Content.Remove(0, index2 + 7).ToString();
            }
            catch
            {
                theThongTin.GioiThieuTomTatVN = "";
                theThongTin.GioiThieuVN = RadNoiDUngVN.Content;
            }

            ThongTinCongTyProvider.IUThongTinCongTys(theThongTin, false);
            String str = "";
            if (IsVN == true)
                str = HangSo.App_VN;
            else
                str = HangSo.App_Other;
            Response.Redirect("EHTFrontPage.aspx?Message=" + str);
        }
    }
}